from boot import QWidget, QHBoxLayout, QLabel, QSizePolicy, QPixmap, Qt


__all__ = ["QQ9InfoWidget"]


class QQ9InfoWidget(QWidget):

    """
    信息组件
    """

    def __init__(self, title: str = "", icon_path: str = "", parent=None, add_style: str = "", title_color: str = "", value_color: str = "#909399"):
        super().__init__(parent)

        self.setFixedSize(500, 40)

        self.main_h_layout = QHBoxLayout()
        self.main_h_layout.setContentsMargins(0, 0, 0, 0)
        self.main_h_layout.setAlignment(Qt.AlignCenter)
        self.setLayout(self.main_h_layout)

        # 图标
        self.icon_label = QLabel()
        self.icon_label.setFixedSize(20, 20)
        self.icon_label.setAlignment(Qt.AlignCenter)
        self.icon_label.setPixmap(QPixmap(icon_path))

        # 标题
        self.title_label = QLabel(title)
        # 将水平布局填满
        self.title_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.title_label.setStyleSheet(
            """
            font-family: "微软雅黑";
            font-size: 15px;
            color: #111111;
            background-color: transparent;
            $
            """.replace("$", add_style).replace("#111111", title_color)
        )

        # 内容
        self.content_label = QLabel()
        self.content_label.setStyleSheet(
            """
            font-family: "微软雅黑";
            font-size: 15px;
            color: #515151;
            background-color: transparent;
            $
            """.replace("$", add_style).replace("#515151", value_color)
        )

        self.main_h_layout.addWidget(self.icon_label)
        self.main_h_layout.addWidget(self.title_label)
        self.main_h_layout.addWidget(self.content_label)

    def set_info(self, content: str):
        self.content_label.setText(content)